package top.continew.admin.generator.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.generator.model.req.TransferHandleReq;
import top.continew.admin.generator.model.resp.TransferChainResp;
import top.continew.admin.generator.service.TaskTransferService;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * 任务转派管理 API
 */
@Tag(name = "任务转派管理 API")
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/task/transfer")
public class TaskTransferController {

    private final TaskTransferService taskTransferService;

    @Operation(summary = "处理转派", description = "接受或退回转派申请")
    @PostMapping("/handle")
    public R<Void> handleTransfer(@Valid @RequestBody TransferHandleReq req) {
        taskTransferService.handleTransfer(req);
        return R.ok();
    }

    @Operation(summary = "查看转派链条", description = "查看任务的完整转派链条")
    @Parameter(name = "taskId", description = "任务ID", example = "1")
    @GetMapping("/chain/{taskId}")
    public R<List<TransferChainResp>> getTransferChain(@PathVariable Long taskId) {
        return R.ok(taskTransferService.getTransferChain(taskId));
    }
}